#include "GlPointLight.h"

#include <windows.h>
#include "GlSpotLight.h"
#include "Utility.h"

namespace GraphicLibrary
{
	//-----------------------------------------------------
	PointLight::PointLight(const float distance)
		: mVisibility(true)
	{
		mColor[0] = mColor[1] = mColor[2] = mColor[3] = 1.0f;
		ZeroMemory(&mSpotLights, sizeof(SpotLight*) * 4);
		for(int i = 0; i != 4; ++i)
		{
			mSpotLights[i] = SpotLight::Create(Utility::Pi * 0.5f, distance);
			mSpotLights[i]->setDirection(i * Utility::Pi * 0.5f);
		}
	}

	//-----------------------------------------------------
	PointLight::~PointLight()
	{
		for(int i = 0; i != 4; ++i)
			delete mSpotLights[i];
	}

	//-----------------------------------------------------
	void PointLight::setVisibility(const bool visible)
	{
		if(mVisibility == visible)
			return;
		mVisibility = visible;
		for(int i = 0; i != 4; ++i)
			mSpotLights[i]->setVisibility(visible);
	}

	//-----------------------------------------------------
	void PointLight::setColor(const float r, const float g, const float b, const float a)
	{
		if(mColor[0] == r && mColor[1] == g && mColor[2] == b && mColor[3] == a)
			return;

		mColor[0] = r;
		mColor[1] = g;
		mColor[2] = b;
		mColor[3] = a;

		for(int i = 0; i != 4; ++i)
			mSpotLights[i]->setColor(r, g, b, a);
	}

	//-----------------------------------------------------
	void PointLight::move(const Position &pos)
	{
		if(mPos == pos)
			return;
		mPos = pos;

		for(int i = 0; i != 4; ++i)
			mSpotLights[i]->move(pos);
	}
}
